<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload = function () {
            var app3 = new Vue({
                el: '#app-3',
                data () {
                    return {
                        msg: 'Weadadlcom'
                    }
                }
            })
            var app4 = new Vue({
                el: '#app-4',
                methods: {
                    reverseMessage: function () {
                        this.message = this.message.split('').reverse().join('')
                    },
                    addp: function () {
//                        this.ps.push({name: '徐磊青', age: 21});
                        var x = {name: this.username, age: this.userage, time: new Date()};
                        this.ps.push(x);

                    },
                    removep: function () {
                        this.ps = [];
                    },
                    remove: function (index) {
                        this.ps.splice(index, 1);
                    }
                },
                data: {
                    message: 'Hello Vue.js!哇咔咔',
                    username: '',
                    userage: '',
                    ps: [
                        {name: '徐磊青', age: '21', time: new Date()},
                        {name: '水影', age: '20', time: new Date()},
                        {name: '风影', age: 000, time: new Date()}
                    ]
                },
                filters: {
                    checkTime: function (v) {
                        return (v.getHours() + ":" + v.getMinutes() + ":" + v.getSeconds())
                    },
                    capitalize: function (value) {
                        if (!value) return ''//'',0,null,
                        value = value.toString()
                        return value.charAt(0).toUpperCase() + value.slice(1)
                    }
                }
            })
        }

    </script>
</head>
<body>
<div id="app-4">
    <!--<ol>-->
    <!--<li v-for="todo in todos">-->
    <!--{{ todo.text }}-->
    <!--</li>-->
    <!--</ol>-->
    <input v-model="username">
    <input v-model="userage">
    <button v-on:click="addp">添加</button>
    <button v-on:click="removep">清空</button>

    <br>
    ///////////////////////////////table
    <table border="1">
        <tr>
            <th>序号</th>
            <th>名字</th>
            <th>年龄</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
        <tr v-for="(p, index) in ps">
            <td>{{index+1}}</td>
            <td>{{p.name|capitalize}}</td>
            <td>{{p.age}}</td>
            <!--<td>{{p.time.getHours()+":"+p.time.getMinutes()+":"+p.time.getSeconds()}}</td>-->
            <td>{{p.time| checkTime}}</td>
            <td>
                <button v-on:click="remove(index)">删除</button>
            </td>
        </tr>
    </table>


</div>
<div id="app-3">

    <p>{{ msg }}</p>
</div>
</body>
</html>